package com.egdd.video.controller;


import com.egdd.video.common.api.ApiResult;
import com.egdd.video.pojo.Albums;
import com.egdd.video.service.iml.AlbumsServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = {"视频合集信息"})
@RequestMapping(value = "/albums")
@RestController
public class AlbumsController {
    @Autowired
    private AlbumsServiceImpl albumsService;

    private static final Logger LOGGER = LoggerFactory.getLogger(AlbumsController.class);

    @ApiOperation("根据分类id获取视频合集列表信息")
    @PostMapping(value = "/getAlbumsByCategoryId")
    public ApiResult getAlbumsByCategoryId(Integer categoryId) {
        return ApiResult.success(albumsService.getAlbumsByCategoryId(categoryId));
    }


    @ApiOperation("查询所有视频合集信息")
    @PostMapping(value = "/getAllAlbums")
    public ApiResult getAllAlbums() {
        return ApiResult.success(albumsService.getAllAlbums());
    }


    @ApiOperation("增加一个视频合集信息")
    @PostMapping(value = "/addAlbums")
    public ApiResult addAlbums(@RequestBody Albums albums) {
        int count = albumsService.addAlbums(albums);
        if (count == 1) {
            return ApiResult.success(count);
        } else {
            return ApiResult.error("操作失败");
        }
    }

    @ApiOperation("根据合集id删除对应的视频合集信息")
    @GetMapping (value = "/delAlbumsById")
    public ApiResult delAlbumsById(int id) {
        int count = albumsService.delAlbumsById(id);
        if (count == 1) {
            return ApiResult.success(count);
        } else {
            return ApiResult.error("操作失败");
        }
    }


}
